package com.shu.lock;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/8/27 9:34
 */

public class Lock_condition {


    public static void main(String[] args) {

        Object o = new Object();


        char[] a1 = "123456".toCharArray();
        char[] b1 = "abcdef".toCharArray();
        char[] c1 = "ABCDEF".toCharArray();




        new Thread(() -> {
            synchronized (o){
                for (final char c : a1) {
                    try {
                        System.out.println(c);
                        o.notifyAll();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t1").start();


        new Thread(() -> {
            synchronized (o){
                for (final char c : b1) {
                    try {
                        System.out.println(c);
                        o.notifyAll();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t2").start();


        new Thread(() -> {
            synchronized (o){
                for (final char c : c1) {
                    try {
                        System.out.println(c);
                        o.notifyAll();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t3").start();
    }

}
